home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_084 / ed / dowrite.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  946b  |  55 lines

  1. /*
  2.  * Copyright 1987 Brian Beattie Rights Reserved.
  3.  *
  4.  * Permission to copy and/or distribute granted under the
  5.  * following conditions:
  6.  *
  7.  * 1). No charge may be made other than resonable charges
  8.  *    for reproduction.
  9.  *
  10.  * 2). This notice must remain intact.
  11.  *
  12.  * 3). No further restrictions may be added.
  13.  *
  14.  */
  15. #include <stdio.h>
  16. #include "tools.h"
  17. #include "ed.h"
  18.  
  19. dowrite(from, to, fname, apflg)
  20. int    from, to;
  21. char    *fname;
  22. int    apflg;
  23. {
  24.     extern FILE    *fopen();
  25.     FILE    *fp;
  26.     int    lin, err;
  27.     int    lines, bytes;
  28.     char    *str;
  29.  
  30.     err = 0;
  31.  
  32.     lines = bytes = 0;
  33.     printf("\"%s\" ",fname);
  34.     if((fp = fopen(fname,(apflg?"a":"w"))) == NULL)
  35.     {
  36.         printf("file open error\n");
  37.         return( ERR );
  38.     }
  39.     for(lin = from; lin <= to; lin++)
  40.     {
  41.         str = gettxt(lin);
  42.         lines++;
  43.         bytes += strlen(str);
  44.         if(fputs(str, fp) == EOF)
  45.         {
  46.             printf("file write error\n");
  47.             err++;
  48.             break;
  49.         }
  50.     }
  51.     printf("%d lines %d bytes\n",lines,bytes);
  52.     fclose(fp);
  53.     return( err );
  54. }
  55.